# -*- coding: utf-8 -*-
"""
Created on Tue Jun  5 21:16:41 2018

@author: sun haiyang
"""
#%%
#首先生成各个模态的groupmean nii文件。
from agilepipe.statics.basiccalculation import Multi_mean

group_filedirpath = r'/media/root/Elements4/XuanWu_last_stat/PET_processing/PET_SN_SR_SSM-6_del-subj24_z'
output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/PET_processing'
Multi_mean([group_filedirpath,output_dirpath])

group_filedirpath = r'/media/root/Elements4/XuanWu_last_stat/CBF_processing/CBF_clear_background_SN_SR_SSM-6_del-subj24_z'
output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/CBF_processing'
Multi_mean([group_filedirpath,output_dirpath])

group_filedirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/ReHo_del-subj24_z'
output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing'
Multi_mean([group_filedirpath,output_dirpath])

group_filedirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/fALFF_del-subj24_z'
output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing'
Multi_mean([group_filedirpath,output_dirpath])

group_filedirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/Dpb_sm-6_del-subj24_z'
output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing'
Multi_mean([group_filedirpath,output_dirpath])



#%%
# the code below is the result filepath of kinds of modality
zpet_dirpath = r'/media/root/Elements4/XuanWu_last_stat/PET_processing/PET_SN_SR_SSM-6_del-subj24_z_mean'
zcbf_dirpath = r'/media/root/Elements4/XuanWu_last_stat/CBF_processing/CBF_clear_background_SN_SR_SSM-6_del-subj24_z_mean'
zfalff_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/fALFF_del-subj24_z_mean'
#zperalff_dirpath = r'/media/root/Elements4/XuanWu_z_sm666_pearson_1002_origin/BOLD_processing/PerAF'
zreho_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/ReHo_del-subj24_z_mean'
zdc_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/Dpb_sm-6_del-subj24_z_mean'

#the code below is the groupmask filepath of kinds of modality
gray_region_mask_dirpath = r'/media/root/Elements4/XuanWu_last/mask/Stanford_altas/intersect_mask'
#此文件夹下是p=0.4/0.5...0.9的文件夹，而p=0.4这个文件夹下是region=1 2 3...7的文件夹，1文件夹下是26个subject的mask

output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/across_spatial/groupmean_Stanford'

#the code below is the used as the excel title.
column_name_list = ['1st_modality_rm','2nd_modality_rm','p_coeff','p_pvalue','p_coeff_z','s_coeff','s_pvalue','s_coeff_z','voxelNUM','modality','region','GM_Probability'] #must set value ,even set column_name_list =[]

grouppath_dict = {'PETvsCBF':[zpet_dirpath,zcbf_dirpath,gray_region_mask_dirpath,output_dirpath],\
                  'PETvsfALFF':[zpet_dirpath,zfalff_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'PETvsReHo':[zpet_dirpath,zreho_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'PETvsDC':[zpet_dirpath,zdc_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'CBFvsfALFF':[zcbf_dirpath,zfalff_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'CBFvsReHo':[zcbf_dirpath,zreho_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'CBFvsDC':[zcbf_dirpath,zdc_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 }
print('grouppath_dict:',grouppath_dict)

from agilepipe.statics.acrossvoxelgroupcorrelate_pear_spear_fishz import Multi_across_voxel_correlate
Multi_across_voxel_correlate([grouppath_dict,column_name_list])

#%%

# the code below is the result filepath of kinds of modality
zpet_dirpath = r'/media/root/Elements4/XuanWu_last_stat/PET_processing/PET_SN_SR_SSM-6_del-subj24_z_mean'
zcbf_dirpath = r'/media/root/Elements4/XuanWu_last_stat/CBF_processing/CBF_clear_background_SN_SR_SSM-6_del-subj24_z_mean'
zfalff_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/fALFF_del-subj24_z_mean'
#zperalff_dirpath = r'/media/root/Elements4/XuanWu_z_sm666_pearson_1002_origin/BOLD_processing/PerAF'
zreho_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/ReHo_del-subj24_z_mean'
zdc_dirpath = r'/media/root/Elements4/XuanWu_last_stat/BOLD_processing/Dpb_sm-6_del-subj24_z_mean'

#the code below is the groupmask filepath of kinds of modality
gray_region_mask_dirpath = r'/media/root/Elements4/XuanWu_last/mask/three_modality_groupmask/intersect_mask'
#此文件夹下是p=0.4/0.5...0.9的文件夹，而p=0.4这个文件夹下是region=1 2 3...7的文件夹，1文件夹下是26个subject的mask

output_dirpath = r'/media/root/Elements4/XuanWu_last_stat/across_spatial/groupmean_three_modality_GM'

#the code below is the used as the excel title.
column_name_list = ['1st_modality_rm','2nd_modality_rm','p_coeff','p_pvalue','p_coeff_fishz','s_coeff','s_pvalue','s_coeff_fishz','voxelNUM','modality','region','GM_Probability'] #must set value ,even set column_name_list =[]

grouppath_dict = {'PETvsCBF':[zpet_dirpath,zcbf_dirpath,gray_region_mask_dirpath,output_dirpath],\
                  'PETvsfALFF':[zpet_dirpath,zfalff_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'PETvsReHo':[zpet_dirpath,zreho_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'PETvsDC':[zpet_dirpath,zdc_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'CBFvsfALFF':[zcbf_dirpath,zfalff_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'CBFvsReHo':[zcbf_dirpath,zreho_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 'CBFvsDC':[zcbf_dirpath,zdc_dirpath,gray_region_mask_dirpath,output_dirpath],\
                 }
print('grouppath_dict:',grouppath_dict)


from agilepipe.statics.acrossvoxelgroupcorrelate_pear_spear_fishz import Multi_across_voxel_correlate
Multi_across_voxel_correlate([grouppath_dict,column_name_list])

#%%

from agilepipe.statics.summarize import Summarize

excel_path = r'C:\Users\Administrator\Desktop\2018-09-01\across_spatial\Stanford\across_voxel_correlate_Stanford.xlsx'
summarize = Summarize(excel_path)
print('before del')
del summarize
print('after del')

#%%
from agilepipe.statics.summarize import Rearrange

rg_excel_filepath = r'C:\Users\Administrator\Desktop\2018-09-01\across_spatial\Stanford\across_voxel_correlate_Stanford.xlsx'
gm_excel_filepath = r'C:\Users\Administrator\Desktop\2018-09-01\across_spatial\three_modality_GM\across_voxel_correlate_tm_GM.xlsx'
output_dirpath = r'C:\Users\Administrator\Desktop\2018-09-01\across_spatial'
Rearrange(rg_excel_filepath,gm_excel_filepath,output_dirpath)

#%%







#%%
